﻿using Gateway.IApplication.BaseInput;
using Gateway.IApplication.Question;
using Gateway.IApplication.Question.Input;
using Gateway.IQuery;
using Gateway.IQuery.Question;
using Gateway.IQuery.Question.Request;
using Gateway.IQuery.Question.Result;

namespace Gateway.UI.Api.Controllers
{
    /// <summary>
    /// 试题服务
    /// </summary>
    public class QuestionController : BaseController
    {
        private readonly IQuestionApp _app;
        private readonly IQuestionQuery _query;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="app"></param>
        /// <param name="query"></param>
        public QuestionController(IQuestionApp app, IQuestionQuery query)
        {
            _app = app;
            _query = query;
        }

        /// <summary>
        /// 创建
        /// </summary>
        /// <param name="input"></param>
        /// <returns>返回主键标识</returns>
        [HttpPost, Route("add")]
        public async Task<bool> Add(CreateQuestionInput input)
        {
            return await _app.Add(input);
        }

        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost, Route("update")]
        public async Task<bool> Update(UpdateQuestionInput input)
        {
            return await _app.Update(input);
        }

        /// <summary>
        /// 更新语言配置
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost, Route("update/langugae")]
        public async Task<bool> UpdateLanguage(UpdateQuestionLanguageInput input)
        {
            return await _app.SetLanguage(input);
        }
        /// <summary>
        /// 删除语言配置
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost, Route("remove/language")]
        public async Task<bool> RemoveLanguage(RemoveInput input)
        {
            return await _app.RemoveLanguage(input);
        }



        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost, Route("remove")]
        public async Task<bool> Remove(RemoveInput input)
        {
            return await _app.Remove(input.Id);
        }

        /// <summary>
        /// 禁用/启用
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost, Route("disable")]
        public async Task<bool> Disable(DisableInput input)
        {
            return await _app.Disable(input.Id, input.Disable);
        }

        /// <summary>
        /// 获取详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet, Route("detail/{id}")]
        public async Task<QuestionDetailResult> GetDetail(string id)
        {
            return await _query.GetDetail(id);
        }
        /// <summary>
        /// 获取基本详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet, Route("detail/simple/{id}")]
        public async Task<QuestionDetailResult> GetSimpleDetail(string id)
        {
            return await _query.GetSimpleDetail(id);
        }
        /// <summary>
        /// 项目分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost, Route("list/page")]
        public async Task<PageResult<QuestionListResult>> GetPageList(QuestionPageListRequest request)
        {
            return await _query.GetPageList(request);
        }


        /// <summary>
        /// 获取列表-可用的
        /// </summary>
        /// <returns></returns>
        [HttpGet, Route("list/available")]
        public async Task<List<QuestionListResult>> GetAllList()
        {
            return await _query.GetAllList();
        }
    }
}
